import {
  Injectable,
  NestInterceptor,
  ExecutionContext,
  CallHandler,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';

@Injectable()
export class YuicInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    console.log('Before...');
    const request = context.switchToHttp().getRequest();
    request.yuicInterInfo = {
      name: 'yuicInterInfo',
    };
    // const now = Date.now();
    return next.handle().pipe(
      map((data) => {
        return {
          data: data,
          status: 0,
          message: '这是一个测试拦截器的请求',
        };
      }),
    );
  }
}
